<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList(1)">
      <el-form-item>
        <el-input v-model="dataForm.keyword.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList(1)">查询</el-button>
        <el-button v-if="isAuth('zhiyao:zydevicedata01:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('zhiyao:zydevicedata01:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
        <el-table-column
            type="index"
            width="50"
        >
        </el-table-column>
      <el-table-column
        prop="userId"
        header-align="center"
        align="center"
        label="用户id">
      </el-table-column>
      <el-table-column
        prop="devId"
        header-align="center"
        align="center"
        label="设备id">
      </el-table-column>
      <el-table-column
        prop="devSn"
        header-align="center"
        align="center"
        label="设备编号">
      </el-table-column>
      <el-table-column
        prop="runSpeed"
        header-align="center"
        align="center"
        label="运行速度">
      </el-table-column>
      <el-table-column
        prop="devTmp"
        header-align="center"
        align="center"
        label="电机温度">
      </el-table-column>
      <el-table-column
        prop="devVoice"
        header-align="center"
        align="center"
        label="声音分贝">
      </el-table-column>
      <el-table-column
        prop="openCount"
        header-align="center"
        align="center"
        label="开门次数">
      </el-table-column>
      <el-table-column
        prop="runTime"
        header-align="center"
        align="center"
        label="总运行时间">
      </el-table-column>
      <el-table-column
        prop="dutyTime"
        header-align="center"
        align="center"
        label="当班时间">
      </el-table-column>
      <el-table-column
        prop="totalTime"
        header-align="center"
        align="center"
        label="累计时间">
      </el-table-column>
      <el-table-column
        prop="dutyOutput"
        header-align="center"
        align="center"
        label="当班产量">
      </el-table-column>
      <el-table-column
        prop="totalOutput"
        header-align="center"
        align="center"
        label="累计产量">
      </el-table-column>
      <el-table-column
        prop="totalRunTime"
        header-align="center"
        align="center"
        label="总运行速度">
      </el-table-column>
      <el-table-column
        prop="drugInfo"
        header-align="center"
        align="center"
        label="药品信息显示">
      </el-table-column>
      <el-table-column
        prop="portInfo"
        header-align="center"
        align="center"
        label="端口预留信息显示">
      </el-table-column>
      <el-table-column
        prop="devSwitchState"
        header-align="center"
        align="center"
        label="设备开关机状态(0关闭,1开启)">
      </el-table-column>
      <el-table-column
        prop="stopSign"
        header-align="center"
        align="center"
        label="急停信号(0无)">
      </el-table-column>
      <el-table-column
        prop="missProSign"
        header-align="center"
        align="center"
        label="缺料信号(0无)">
      </el-table-column>
      <el-table-column
        prop="missBagSign"
        header-align="center"
        align="center"
        label="缺囊信号(0无)">
      </el-table-column>
      <el-table-column
        prop="airSign"
        header-align="center"
        align="center"
        label="气压信号(0无)">
      </el-table-column>
      <el-table-column
        prop="errorSign"
        header-align="center"
        align="center"
        label="变频故障信号(0无)">
      </el-table-column>
      <el-table-column
        prop="proCode"
        header-align="center"
        align="center"
        label="产品代码">
      </el-table-column>
      <el-table-column
        prop="proName"
        header-align="center"
        align="center"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="proNum"
        header-align="center"
        align="center"
        label="产品批号">
      </el-table-column>
      <el-table-column
        prop="operatorLevel"
        header-align="center"
        align="center"
        label="操作员级别">
      </el-table-column>
      <el-table-column
        prop="operatorName"
        header-align="center"
        align="center"
        label="操作员">
      </el-table-column>
      <el-table-column
        prop="switchWay"
        header-align="center"
        align="center"
        label="手动/自动 (0自动/1手动)">
      </el-table-column>
      <el-table-column
        prop="pointAction"
        header-align="center"
        align="center"
        label="主机点动(0否)">
      </el-table-column>
      <el-table-column
        prop="linkAction"
        header-align="center"
        align="center"
        label="主机联动(0否)">
      </el-table-column>
      <el-table-column
        prop="airPointAction"
        header-align="center"
        align="center"
        label="真空泵点动(0否)">
      </el-table-column>
      <el-table-column
        prop="airLinkAction"
        header-align="center"
        align="center"
        label="真空泵联动(0否)">
      </el-table-column>
      <el-table-column
        prop="beforeSwitchTime"
        header-align="center"
        align="center"
        label="切换前工作时间">
      </el-table-column>
      <el-table-column
        prop="afterSwitchTime"
        header-align="center"
        align="center"
        label="切换后工作时间">
      </el-table-column>
      <el-table-column
        prop="pushTime"
        header-align="center"
        align="center"
        label="放料时间">
      </el-table-column>
      <el-table-column
        prop="airDelayTime"
        header-align="center"
        align="center"
        label="空囊上料延时时间">
      </el-table-column>
      <el-table-column
        prop="hostDelayTime"
        header-align="center"
        align="center"
        label="主机延时时间">
      </el-table-column>
      <el-table-column
        prop="missproDelayTime"
        header-align="center"
        align="center"
        label="缺料延时时间">
      </el-table-column>
      <el-table-column
        prop="missbagDelayTime"
        header-align="center"
        align="center"
        label="缺囊延时时间">
      </el-table-column>
      <el-table-column
        prop="addDelayTime"
        header-align="center"
        align="center"
        label="加料电机延时时间">
      </el-table-column>
      <el-table-column
        prop="terminalGps"
        header-align="center"
        align="center"
        label="经纬度">
      </el-table-column>
      <el-table-column
        prop="terminalTmp"
        header-align="center"
        align="center"
        label="终端温度">
      </el-table-column>
      <el-table-column
        prop="terminalState"
        header-align="center"
        align="center"
        label="终端状态">
      </el-table-column>
      <el-table-column
        prop="terminalKey"
        header-align="center"
        align="center"
        label="终端key">
      </el-table-column>
      <el-table-column
        prop="terminalName"
        header-align="center"
        align="center"
        label="终端名称">
      </el-table-column>
      <el-table-column
        prop="terminalConnectState"
        header-align="center"
        align="center"
        label="终端连接状态">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
    import AddOrUpdate from './zydevicedata01-add-or-update'
    export default {
    data () {
      return {
        dataForm: {
          keyword: {
            key: ''
            // ,pId: ''
          }
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList (formSearch) {
        // 搜索框来源
        if (formSearch === 1) {
          this.pageIndex = 1
        }
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/zhiyao/zydevicedata01/list'),
          method: 'post',
          data: this.$http.adornData({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keyword': this.dataForm.keyword
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        // this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        this.$confirm(`确定[${id ? '删除' : '批量删除'}]?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/zhiyao/zydevicedata01/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
